package com.xyu.Config;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableRabbit
//@EnableRabbit‌注解在Spring Boot应用中用于启用基于注解的RabbitMQ消息处理功能。
public class RabbitMQConfig {
   @Bean
   public FanoutExchange fanoutExchange() {
    return new FanoutExchange("exchange_my");
   }
    // 定义不同名称的消息队列
    @Bean
    public Queue smsQueue() {
        return new Queue("fanout_queue_tem", true);  // 队列持久化
    }
    @Bean
    public Queue emailQueue() {
        return new Queue("fanout_queue_num", true);  // 队列持久化
    }
    // 将消息队列与交换器绑定
    @Bean
    public Binding smsBinding() {
        return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
    }
    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
    }
    @Bean
    public MessageConverter messageConverter(){
 return new Jackson2JsonMessageConverter();
 }
    //路由
    @Bean
    public DirectExchange directExchange(){
       return new DirectExchange("routing_exchange");
    }
    @Bean
    public Queue routeQueue(){
       return new Queue("routing_queue_all",true);
    }
    @Bean
    public Binding routeBinding(){return BindingBuilder.bind(routeQueue()).to(directExchange()).withQueueName();}
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topic_exchange");
    }
    @Bean
    public Queue topic_queue_email(){
       return new Queue("topic_queue_email",true);
    }
    @Bean
    public BindingBuilder.TopicExchangeRoutingKeyConfigurer topicBinding(){return BindingBuilder.bind(topic_queue_email()).to(topicExchange());}



}